<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "login_log".
 *
 * @property integer $id
 * @property integer $uid
 * @property integer $created_at
 * @property integer $updated_at
 * @property string $ip
 */
class LoginLog extends \common\models\BaseActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'login_log';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid'], 'required'],
            [['uid', 'created_at', 'updated_at'], 'integer'],
            [['ip'], 'string', 'max' => 64],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => 'Uid',
            'created_at' => 'Created At',
            'updated_at' => '更新时间',
            'ip' => 'ip',
        ];
    }

    /**
     * @param bool $insert
     * @return bool
     */
    public function beforeSave($insert)
    {
        if($insert){
            $this->ip = Yii::$app->getRequest()->getUserIP();
            $this->updated_at = time();
        }
        return parent::beforeSave($insert); // TODO: Change the autogenerated stub
    }
}
